﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// Summary description for TypesManager
/// </summary>
public class TypesManager
{
    private ArrayList listTypes = new ArrayList();
    private int _CurrentPosition = -1;

	public TypesManager()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public void BeforeFirst()
    {
        _CurrentPosition = -1;
    }

    public bool Next()
    {
        _CurrentPosition++;
        if (_CurrentPosition < listTypes.Count)
            return true;
        else
            return false;
    }

    public PlaceType GetCurrent()
    {
        return (PlaceType)listTypes[_CurrentPosition];
    }

    public PlaceType GetFirstPoint()
    {
        PlaceType p = null;
        if (listTypes.Count > 0)
        {
            p = (PlaceType)listTypes[0];
        }
        return p;
    }

    public static void FillDDL(DropDownList ddl)
    {
        try
        {
            SqlConnection conn = MapConnection.GetConnection();
            string sqlSelect = "SELECT typeid,typename,description FROM types";
            SqlDataAdapter adapter = new SqlDataAdapter(sqlSelect, conn);
            DataSet ds = new DataSet();
            adapter.Fill(ds, "tblTypes");

            ddl.DataSource = ds.Tables[0];
            ddl.DataTextField = "typename";
            ddl.DataValueField = "typeid";
            ddl.DataBind();

            ListItem item0 = new ListItem();
            item0.Text = "---All Places---";
            item0.Value = "0";
            ddl.Items.Insert(0, item0);

            MapConnection.CloseConnetion(conn);
        }
        catch (Exception)
        {
            
        }
    }

    //public PlacesManager()
    //{
    //    this._PlaceType = PlaceType;
    //    this._PlaceUser = PlaceUser;

    //    try
    //    {
    //        SqlConnection conn = MapConnection.GetConnection();
    //        string sqlSelect = "SELECT placeid,title,description,image,longitude,latitude,type,userid FROM places WHERE type = @type AND userid = @userid";
    //        SqlCommand command = new SqlCommand(sqlSelect, conn);
    //        command.Parameters.AddWithValue("@type",this._PlaceType);
    //        command.Parameters.AddWithValue("@userid", this._PlaceUser);

    //        SqlDataReader data = command.ExecuteReader();
    //        while (data.Read())
    //        {
    //            Place place = new Place();
    //            place.PlaceID = data.GetInt32(0);
    //            place.PlaceTitle = data.GetString(1);
    //            place.PlaceDescription = data.GetString(2);
    //            place.PlaceImage = data.GetString(3);
    //            place.PlaceLat = data.GetFloat(4);
    //            place.PlaceLng = data.GetFloat(5);
    //            place.PlaceType = data.GetInt32(6);
    //            place.PlaceUserID = data.GetInt32(7);

    //            listPlaces.Add(place);
    //        }
            
    //        MapConnection.CloseConnetion(conn);
    //    }
    //    catch (Exception ex)
    //    {
            
    //    }
    //}
}
